package com.amumu.drama.admin.modules.game.controller;

import com.amumu.drama.common.base.api.CommonPage;
import com.amumu.drama.common.base.api.CommonResult;
import com.amumu.drama.common.modules.category.dto.GameBatchHandlerDto;
import com.amumu.drama.common.modules.category.dto.GameDto;
import com.amumu.drama.common.modules.category.dto.GameQueryDto;
import com.amumu.drama.common.modules.category.service.GameService;
import com.amumu.drama.common.modules.category.vo.GameVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品分类管理Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "微丸子-游戏管理")
@RequestMapping("/game")
public class GameController {
    @Autowired
    private GameService gameService;

    @ApiOperation("添加/编辑游戏")
    @RequestMapping(value = "/addOrUpdateGame", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addOrUpdateGame(@Validated @RequestBody GameDto anchorDto) {
        return gameService.addOrUpdateGame(anchorDto);
    }

    @ApiOperation("删除游戏")
    @RequestMapping(value = "/delete/{gameId}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult deleteGame(@PathVariable Long gameId) {
        return gameService.deleteGame(gameId);
    }

    @ApiOperation("根据执行策略批量操作")
    @RequestMapping(value = "/batchWithexecutionStrategy", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult batchWithexecutionStrategy(@RequestBody @Validated GameBatchHandlerDto gameBatchHandlerDto) {
        return gameService.batchWithexecutionStrategy(gameBatchHandlerDto.getGameIds(), gameBatchHandlerDto.getPerformOperations(), gameBatchHandlerDto.getExecutionStrategy());
    }

    @ApiOperation("查询游戏列表")
    @RequestMapping(value = "/pageGameList", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<GameVo>> pageGameList(@Validated @RequestBody GameQueryDto gameQueryDto) {
        return CommonResult.success(gameService.pageGameList(gameQueryDto));
    }

    @ApiOperation("修改排序")
    @RequestMapping(value = "/editSort/{gameId}/{sort}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult editSort(@PathVariable Long gameId, @PathVariable Integer sort) {
        return gameService.editSort(gameId, sort);
    }

    @ApiOperation("获取游戏详情")
    @RequestMapping(value = "/getGameInfo/{gameId}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<GameVo> getGameInfo(@PathVariable Long gameId) {
        return gameService.getGameInfo(gameId);
    }
}
